# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon, xguo

from tornado import gen
from coin.exchange.base.rest.private_queryer_context_base import PrivateQueryContextBase


class SpotPrivateQueryContextBase(PrivateQueryContextBase):
  @gen.coroutine
  def _run_query(self):
    self._querying = True
    self._logger.debug('Start querying %d products' % len(self._products))
    try:
      self._query_balance()
      for product in self._products:
        self._query_list_orders(product)
        self._query_fills(product)
    finally:
      self._querying = False
      if not self._stopped:
        self._logger.debug('Query done')
      else:
        self._logger.debug('Stopped')
